package com.beiding.workordersystem.common.helper;

import org.springframework.stereotype.Component;

import javax.servlet.http.HttpSession;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Component
public class MySessionContext {
    private Map<String,HttpSession> sessionMap;

    public MySessionContext() {
        sessionMap = new ConcurrentHashMap<>();
    }

    public synchronized void addSession(HttpSession session) {
        if (session != null) {
            sessionMap.put(session.getId(), session);
        }
    }

    public synchronized void delSession(HttpSession session) {
        if (session != null) {
            sessionMap.remove(session.getId());
        }
    }

    public Map<String, HttpSession> getSessionMap() {
        return sessionMap;
    }
}